package cn.mafangui.hotel.controller.worker;

import cn.mafangui.hotel.entity.Dishes;
import cn.mafangui.hotel.entity.DishesManager;
import cn.mafangui.hotel.response.AjaxResult;
import cn.mafangui.hotel.response.MsgType;
import cn.mafangui.hotel.response.ResponseTool;
import cn.mafangui.hotel.service.DishesManagerService;
import cn.mafangui.hotel.service.DishesService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

import static org.springframework.web.bind.annotation.RequestMethod.GET;

/**
 * @author ：Angular
 * @ProjectName: hotel
 * @Package: cn.mafangui.hotel.controller.worker
 * @ClassName: OpNoticeController
 * @date ：Created in 2021/4/24 10:35
 * @description：公告管理控制层
 * @modified By：
 * @version: v1.0.0$
 */
@RestController
@RequestMapping(value = "/op/dishesmanager")
public class OpDishesManagerController {
    @Autowired
    private DishesManagerService dishesManagerService;

    /**
     * 添加公告
     * 订单状态默认为未付款状态
     */
    @RequestMapping(value = "/add")
    public AjaxResult addNotice(String dishName, String dishPrice) {
        DishesManager dishesManager = new DishesManager(0, dishName, dishPrice);
        int re = dishesManagerService.insert(dishesManager);
        if (re != 1) return ResponseTool.failed(MsgType.FAILED);
        return ResponseTool.success("添加成功.");
    }


    @RequestMapping(value = "/delete")
    public AjaxResult deleteNotice(String orderId) {
        int re = dishesManagerService.delete(Integer.parseInt(orderId));
        if (re != 1) return ResponseTool.failed(MsgType.FAILED);
        return ResponseTool.success("删除成功.");
    }


    @RequestMapping(value = "")
    public AjaxResult getAllDishesManager() {
        return ResponseTool.success(dishesManagerService.AllDishesManager());
    }

    @RequestMapping(value = "/count")
    public AjaxResult getDishesCount() {
        return ResponseTool.success(dishesManagerService.getDishesCount());
    }

    /**
     * 根据id号查询
     *
     * @param id
     * @return
     */
    @RequestMapping(value = "/{id}")
    public AjaxResult getById(@PathVariable Integer id) {
        return ResponseTool.success(dishesManagerService.selectById(id));
    }


}
